function HandlePLastUpdated(gui, user, date, options, data) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._data = data;
  this._popupBox = new ModulePopupBoxSimple();
  
  this._createElements();
};
HandlePLastUpdated.prototype._createElements = function() {
  var _self = this;
  this._models = this._data['pz_model'];
  this._states = this._data['pz_model_state'];
  this._transitions = this._data['pz_model_transition'];
  this._search = { dateFrom: '',
                   dateTo: '',
                   user: ''
                 };
  tr = this._gui.table.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 9;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePLastUpdated.prototype._loadData = function() {
  this._events = null;
  this._parameters = null;
  this._retrieveEvents(1);
};

HandlePLastUpdated.prototype._verifyData = function() {
  if (this._events) {
    this._updateElements();
  }
};

HandlePLastUpdated.prototype._retrieveEvents = function(page, condition, pos) {
  var _self = this;
  var args =((condition) ? '&c=' + encodeURIComponent(condition) : '') + '&p=' + page;
  new RequestUtils()._mysql('lastupdated', args, function(result, params) { _self._events = result.data;
                                                                            _self._parameters = result;
                                                                            _self._verifyData.call(_self);
                                                                          }, {pos: (pos) ? pos: null});
};

HandlePLastUpdated.prototype._updateElements = function() {
  var _self = this;
  DOMUtils.removeTableRows(this._gui.table, 1);
  DOMUtils.removeChildElements(this._gui.page);
  this._gui.table.style.color = '#444';
  this._gui.table.style.fontSize = '12px';
  
  /*---Last Updated-----*/
  if (this._events.length == 0) {
    tr = this._gui.table.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 10;
    td.style.height = '25px';
    td.style.backgroundColor = '#ffffff';
    td.style.textAlign = 'left';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode('n/a'));
  }
  for (var i = 0, il = this._events.length; i < il; i++) {
    var event = this._events[i];
    tr = this._gui.table.insertRow(-1);
    
    tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#f4f4f4' : '#fff';
    td = tr.insertCell(-1);
    td.style.height = '20px';
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((event.branch) ? event.branch : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((event.model_id != 2) ? (event.customer_id != 0) ? PPublishUtils.customerId(event.customer_id) : '-' : 'Parcel ' + event.code));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((event.created_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(event.created_date)) : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((event.received_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(event.received_date)) : '-'));
    
    if (event.model_id == 3) {
      td = tr.insertCell(-1);
      td.style.padding = '0 10px 0 5px';
      td.style.borderRight = 'solid 1px #bbb';
      td.colSpan = 2;
      var span = document.createElement('span');
      span.style.fontWeight = 'bold';
      span.appendChild(document.createTextNode('From: '));
      td.appendChild(span);
      td.appendChild(document.createTextNode((event.custom_assigner) ? event.custom_assigner : '-'));
    } else {
      td = tr.insertCell(-1);
      td.style.padding = '0 10px 0 5px';
      td.style.borderRight = 'solid 1px #bbb';
      td.appendChild(document.createTextNode((event.photographer) ? event.photographer : '-'));
      
      td = tr.insertCell(-1);
      td.style.padding = '0 10px 0 5px';
      td.style.borderRight = 'solid 1px #bbb';
      td.appendChild(document.createTextNode((event.photographer2) ? event.photographer2 : '-'));
    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if (event.model_id == 3) {
      var span = document.createElement('span');
      span.style.fontWeight = 'bold';
      span.appendChild(document.createTextNode('To: '));
      td.appendChild(span);
      td.appendChild(document.createTextNode((event.custom_assignee) ? event.custom_assignee : '-'));
    } else {
      td.appendChild(document.createTextNode((event.designer) ? event.designer : '-'));
    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    var state = PPublishUtils.object(event.s_id, this._states);
    var transition = PPublishUtils.object(event.t_id, this._transitions);
    var str = ((state) ? state.name : '') + ((transition) ? '(' + transition.name + ')' : '') + ((event.message) ? ' / ' + event.message : '') + ((event.message && event.overdue) ? ' / ' : '') + ((event.overdue) ? 'Overdue Reason: ' + event.overdue : '')
    td.appendChild(document.createTextNode((str) ? str: '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    td.appendChild(document.createTextNode((event.user) ? event.user : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 10px 0 5px';
    td.appendChild(document.createTextNode((event.date) ? SimpleDate.format(SimpleDate.fromStamp(event.date)) : '00/00/0000'));
  }
  /*--PAGINATION--*/
  if (this._parameters.total > this._parameters.size) {
    new ModulePagination2(document, this._gui.page, 500, 50, this._user, this._date, {page: this._parameters.page, total: this._parameters.total, limit: this._parameters.size, callbackFunc: function(page, condition) { _self._retrieveEvents.call(_self, page, _self._parameters.condition); }, context: this});
  }
  /*----SEARCH-----*/
  this._eventSearch(this._gui, function(condition, pos) { _self._retrieveEvents.call(_self, 1, condition, pos); });
};

HandlePLastUpdated.prototype._eventSearch = function(gui, callbackFunc) {
  var _self = this;
  this._callbackFunc = callbackFunc;
  gui.user.value = this._search.user;
  gui.user.onchange = function() { _self._search.user = this.value; };
  gui.user.onkeydown = function() { _self._search.user = this.value; };
  gui.user.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                      if (code == 13) {
                                        _self._callbackFunc.call(_self, _self._toString(_self._search), DOMUtils.findPos(this));
                                      }
                                    };
  gui.dateFrom.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
  gui.dateFrom.onclick = function() { var context = this;
                                      _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
                                      return false;
                                    };
  gui.dateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                          if (code == 13) {
                                            _self._callbackFunc.call(_self, _self._toString(_self._search), DOMUtils.findPos(this));
                                          }
                                        };
  gui.dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
  gui.dateTo.onclick = function() { var context = this;
                                    _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
                                    return false;
                                  };
  gui.dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                        if (code == 13) {
                                          _self._callbackFunc.call(_self, _self._toString(_self._search), DOMUtils.findPos(this));
                                        }
                                      };
 gui.search.onclick = function() { _self._callbackFunc.call(_self, _self._toString(_self._search), DOMUtils.findPos(this)); };
};

HandlePLastUpdated.prototype._toString = function(search) {
  var str = '';
  str = ((search.user == '') ? '1 = 1' : '(t4.name LIKE \'%' + search.user + '%\')')  + ' AND ' + ((search.dateFrom) ? '(t.date >= \'' + SimpleDate.toStamp(search.dateFrom ) + '\')' : '1 = 1') + ' AND ' + ((search.dateTo) ? '(t.date <= \'' + SimpleDate.toStamp(search.dateTo) + '\')' : '1 = 1');
  return str;
};

HandlePLastUpdated.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePLastUpdated.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePLastUpdated.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};